package com.source.barcodeMachineStatus.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.barcodeMachineStatus.entity.BarcodeMachineAlert;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.source.barcodeMachineStatus.vo.BarcodeMachineAlertVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fengq
 * @since 2021-02-27
 */
@Repository
public interface BarcodeMachineAlertMapper extends BaseMapper<BarcodeMachineAlert> {

    String SQL="select DISTINCT a.alterId,a.barcodeMachineNumber,a.faultInfo,a.faultStatus,a.faultTime,a.remarks,a.isRead,c.stallsName,d.`name`\n" +
            "from barcode_machine_alert as a ,house_machine_grant as b ,stalls as c,sys_user as d \n" +
            "where a.barcodeMachineNumber=b.machineNumber\n" +
            "and a.isDelete=0  \n" +
            "and b.isDelete=0  \n" +
            "and c.isDelete=0\n" +
            "and c.stallsId=b.stallsGrantId\n" +
            "and d.userId=c.userId";
    /**
     * getOneVoById 根据id进行查询，查询结果封装进BarcodeMachineAlertVo
     * @param alterId
     * @return
     */
    @Select(SQL + "  and alterId=${alterId}\n")
    BarcodeMachineAlertVo getOneVoById(@Param("alterId") String alterId);

    /**
     * getPageVo 查询所有记录
     * @return IPage<BarcodeMachineAlertVo>
     * @param page
     */
    @Select(SQL)
    IPage<BarcodeMachineAlertVo> getPageVo(Page<BarcodeMachineAlertVo> page);

    /**
     * getLikeVo 多字段模糊查询
     * @param page
     * @param keyword
     * @return
     */
    @Select("<script>select DISTINCT a.alterId,a.barcodeMachineNumber,a.faultInfo,a.faultStatus,a.faultTime,a.remarks,a.isRead,c.stallsName,d.`name`\n" +
            "from barcode_machine_alert as a ,house_machine_grant as b ,stalls as c,sys_user as d \n" +
            "where a.barcodeMachineNumber=b.machineNumber\n" +
            "and a.isDelete=0  \n" +
            "and b.isDelete=0  \n" +
            "and c.isDelete=0\n" +
            "and c.stallsId=b.stallsGrantId\n" +
            "and d.userId=c.userId \n" +
            "<if test=\"keyword!=null ang keyword!='' \" >and (concat_ws(',',a.barcodeMachineNumber,stallsName,faultStatus,faultTime,a.createDate,isRead,d.`name`) like \"%${keyword}%\" \n" +
            "or faultInfo like \"%${keyword}%\"\n" +
            "or remarks like \"%${keyword}%\") </if></script>")
    IPage<BarcodeMachineAlertVo> getLikeVo(Page<BarcodeMachineAlertVo> page,@Param("keyword") String keyword);

}
